package com.ai.nsa.utils.lock;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Map;

/**
 * Map 缓存
 *
 * @author Feng Chen
 */
public class MapCache {


    public static Map newLRUCache(final int size, boolean threadSafe) {

        Map cache = new LinkedHashMap(size + 1, .75f, true) {

            @Override
            protected boolean removeEldestEntry(Map.Entry eldest) {
                return size() > size;
            }

        };


        return threadSafe ? Collections.synchronizedMap(cache) : cache;
    }

}
